import { _get,_post } from "@/api/index"
import api from "@/api/api_address"
import { HOST_URL } from "@/api/host"

//测试
export const getNews =(data)=>{
	// console.log(data)
	// console.log(api.news);
	let req = {
		url: api.home.news,
		data
	};
	return _get(req);
}

export const getUserNews = (data)=>{
	let req = {
		url:api.user.getusernews,
		data
	};
	return _get(req)
}

//获取首页列表
export const getTodyLook =(data)=>{
	// console.log(data);
	let req = {
		url: api.home.todaylook,
		data
	};
	return _get(req);
}

//获取搜索列表
export const getSearch = (data)=>{
	// console.log(data);
	let req = {
		url:api.search.searchlist,
		data
	};
	return _post(req)
}

//获取主题列表
export const getCategory = (data)=>{
	// console.log(data);
	let req = {
		url:api.search.categorylist,
		data
	};
	return _post(req)
}

//新闻详情
export const getDetail = (data)=>{
	let req = {
		url:api.detail.newsdetail,
		data
	};
	return _get(req)
}

//登录
export const login = (data)=>{
	let req={
		url:api.user.login,
		data
	}
	return _post(req)
}

//注册
export const register = (data)=>{
	// console.log(data);
	let req = {
		url:api.user.register,
		data
	};
	return _post(req)
}

//获取用户个人信息
export const getUser = (data)=>{
	let req = {
		url:api.user.getuserinfo,
		data
	};
	return _get(req)
}

//增加浏览记录
export const addLook = (data)=>{
	let req={
		url:api.user.addlook,
		data
	};
	return _post(req)
}

//删除浏览记录
export const removeLook = (data)=>{
	let req={
		url:api.user.removelook,
		data
	};
	return _post(req)
}

//获取浏览记录
export const getLook = (data)=>{
	let req={
		url:api.user.getlook,
		data
	};
	return _get(req)
}

//收藏
export const addBookmark = (data)=>{
	let req = {
		url:api.bookmark.addbookmark,
		data
	};
	return _post(req)
}

//取消收藏
export const removeBookmark = (data)=>{
	let req = {
		url:api.bookmark.removebookmark,
		data
	};
	return _post(req)
}

//获取收藏
export const getBookmark = (data)=>{
	let req = {
		url :api.bookmark.getbookmark,
		data
	};
	return _get(req)
}

//获取收藏列表
export const getBookmarkList = (data)=>{
	let req = {
		url :api.bookmark.getbookmarklist,
		data
	}
	return _get(req)
}

//点赞
export const addLike = (data)=>{
	let req={
		url:api.like.addlike,
		data
	};
	return _post(req)
}

//取消点赞
export const removeLike = (data)=>{
	let req={
		url:api.like.removelike,
		data
	};
	return _post(req)
}

//获取点赞数量
export const likeCount = (data)=>{
	let req = {
		url:api.like.likecount,
		data
	};
	return _get(req)
}

//获取点赞列表
export const getLike = (data)=>{
	let req={
		url:api.like.getlike,
		data
	};
	return _get(req)
}

//关注
export const addFollow = (data)=>{
	let req={
		url:api.follow.addfollow,
		data
	};
	return _post(req)
}

//取消关注
export const removeFollow = (data)=>{
	let req = {
		url:api.follow.removefollow,
		data
	};
	return _post(req)
}

//获取关注数量
export const follwerCount = (data)=>{
	// console.log("follower",data);
	let req = {
		url:api.follow.follwercount,
		data
	};
	return _get(req)
}

//获取粉丝数量
export const fansCount = (data)=>{
	// console.log("fans",data);
	let req = {
		url:api.follow.fanscount,
		data
	};
	return _get(req)
}

//获取用户关注列表
export const getFollow = (data)=>{
	let req = {
		url:api.follow.getfollow,
		data
	};
	return _get(req)
}

//获取用户粉丝列表
export const getFans = (data)=>{
	let req = {
		url:api.follow.getfans,
		data
	};
	return _get(req)
}

// 上传头像的接口
export const upLoadImg = (data)=>{
	console.log("2222====>",data);
	let req = {
		url:api.user.uploadImg,
		data
	};
	return _post(req)
}
// 保存头像的接口
export const saveImg = (data)=>{
	let req={
		url:api.user.saveImg,
		data
	};
	return _post(req)
}
// 删除头像的接口
export const deteleImg=(data)=>{
	let req = {
		url:api.user.deleteImg,
		data
	};
	return _post(req)
}

export const newsArea=(data={})=>{
	 return new Promise((resolve,reject)=>{
		 uni.request({
		 	url:`${HOST_URL}/news/area`,
			data:data,
			method:"GET",
			success(content){
				let{data,errMsg}=content
				if(errMsg=='request:ok'){
					resolve(data)
				}else{
					resolve({
						code:-1,
						msg:"数据无效"
					})
				}
			},
			fail(err) {
				reject(err)
			}
		 })
	 })
 }

// 一级评论
export const oneCommon = (data={})=>{
	return new Promise((resolve,reject)=>{
		uni.request({
			url:`${HOST_URL}/news/common`,
			data:data,
			// header:token,
			method:"POST",
			success(content){
				let{data,errMsg}=content
				if(errMsg=='request:ok'){
					resolve(data)
				}else{
					resolve({
						code:-1,
						msg:"数据无效"
					})
				}
			},
			fail(err) {
				reject(err)
			}
		})
	})
}

//二级评论
 export const commonChild = (data={})=>{
 	return new Promise((resolve,reject)=>{
 		uni.request({
 			url:`${HOST_URL}/news/commonChild`,
 			data:data,
 			// header:token,
 			method:"POST",
 			success(content){
 				let{data,errMsg}=content
 				if(errMsg=='request:ok'){
 					resolve(data)
 				}else{
 					resolve({
 						code:-1,
 						msg:"数据无效"
 					})
 				}
 			},
 			fail(err) {
 				reject(err)
 			}
 		})
 	})
 }
 // 检查一级评论
 export const getCommon = (data={})=>{
 	 return new Promise((resolve,reject)=>{
 		 uni.request({
 		 	url:`${HOST_URL}/news/inCommon`,
 			data:data,
 			method:"GET",
 			success(content){
 				let {data,errMsg}=content;
 				if(errMsg=='request:ok'){
 					resolve(data)
 				}else{
 					resolve({
 						code:-1,
 						msg:"数据无效"
 					})
 				}
 			},
 			fail(err) {
 				reject(err)
 			}	
 		 })
 	 })
 }
 
 // 检查二级评论
 export const childList = (data={})=>{
	 return new Promise((resolve,reject)=>{
		 uni.request({
		 	url:`${HOST_URL}/news/selectId`,
			data:data,
			method:"GET",
			success(content){
				let {data,errMsg}=content;
				if(errMsg=='request:ok'){
					resolve(data)
				}else{
					resolve({
						code:-1,
						msg:"数据无效"
					})
				}
			},
			fail(err) {
				reject(err)
			}	
		 })
	 })
 }